clear all
set type double

/**/
use ../../data/mongolia/mongolia.dta, replace 
rename win winner
rename contract_id contract_id_original
egen contract_id = group(auction_id)

gen date0 = ustrregexra(date, "[0-9]{2}:[0-9]{2}","")
cap drop deadline_bidding
gen bid_date = date(date0, "YMD")
format bid_date %td
destring firm_id, replace ignore("""")


do ../modules/backlog_construction
backlog_construction "" ""

save ../../data/mongolia/sample_mongolia_07apr22.dta, replace /*fix sample*/

scatter delta1w bid_date if abs(delta1w) < .2, msize(vsmall)


ss
*/

clear all
use source/mongolia_backlog_07apr22.dta, replace
*use source/mongolia_backlog_22feb22.dta, replace
global threshold_rd = .2
global threshold_fg = .05

rename delta1w delta
rename delta2w delta_placebo


/* auctions in which the lowest bidder wins*/
cap drop temp
/*
gen abnormally_low = (pct_bid_first < .2)
bys abnormally_low contract_id: egen bid_rank_first_p20_t = rank(bid_first) if abnormally_low == 0, t
gen temp = (winner == 1 & bid_rank_first_p20_t == 1)
bys contract_id: egen sFPSB = max(temp)

*/

*keep if N_bidders >= 3

/*Figures and Tables*/
do ../sub_common/graph_table_sub
/* rblog */
drawgraph_comb delta rblog "" "results" "Mongolia" "graph_stats" "mnrblog" "Rolling Backlog; Mongolia"

/* lnblog */
drawgraph_comb delta lnblog "" "results" "Mongolia" "graph_stats" "mnlnblog" "Log Backlog; Mongolia"





